﻿
@foreach (var item in MenuItems)
{
    <div class="nav-item px-3">
        @if (item.Node.ID == "1")
        {
            <NavLink class="nav-link" href="@item.Node.URL" @onclick="() => ToggleSubMenu(item)" Match="NavLinkMatch.All">
                <span class="oi  oi-home" aria-hidden="true"></span> @item.Node.Text
            </NavLink>
        }
        else
        {
            <NavLink class="nav-link" href="@item.Node.URL" @onclick="() => ToggleSubMenu(item)">
                <span class="oi" aria-hidden="true"></span> @item.Node.Text
            </NavLink>
        }

        @if (item.Children.Any() && item.Node.Expanded)
        {
            <T_Menu MenuItems="item.Children" />
        }

    </div>
}
@* @foreach (var item in MenuItems)
{

    <SubMenu Key="sub1" Title="@item?.Node?.Text">
        @if (item.Children.Any() && item.Node.Expanded)
        {
            foreach (var item2 in item.Children)
            {
                <MenuItem Key="">"@item2.Node.Text</MenuItem>
            }
            <T_Menu MenuItems="item.Children" />

        }
    </SubMenu>

} *@
@code {
    [Parameter]
    public List<BlazorDemo.Data.TreeNode> MenuItems { get; set; }=new();

    private void ToggleSubMenu(BlazorDemo.Data.TreeNode item)
    {
        item.Node.Expanded = !item.Node.Expanded;
    }
}
